package com.zhou.spider;

import us.codecraft.webmagic.selector.Html;

/**
 * @Author: zhouweixin
 * @Description:
 * @Date: Created in 18:19 2019/1/1
 * @Modified By:
 */
public class Patent {
    public String patentType;
    public String patentNum;
    public String firstInventor;
    public String pubDate;
    public String name;
    public String inventor;
    public String applicant;
    public String assignee;
    public String familyId;
    public String appNum;
    public String appDate;
    public String usClc;
    public String cpcClc;
    public String ipcClc;
    public String reUsPatent;
    public String reFoPatent;
    public String reOther;

    @Override
    public String toString() {
        return "Patent{" +
                "patentType='" + patentType + '\'' +
                ", patentNum='" + patentNum + '\'' +
                ", firstInventor='" + firstInventor + '\'' +
                ", pubDate='" + pubDate + '\'' +
                ", name='" + name + '\'' +
                ", inventor='" + inventor + '\'' +
                ", applicant='" + applicant + '\'' +
                ", assignee='" + assignee + '\'' +
                ", familyId='" + familyId + '\'' +
                ", appNum='" + appNum + '\'' +
                ", appDate='" + appDate + '\'' +
                ", usClc='" + usClc + '\'' +
                ", cpcClc='" + cpcClc + '\'' +
                ", ipcClc='" + ipcClc + '\'' +
                ", reUsPatent='" + reUsPatent + '\'' +
                ", reFoPatent='" + reFoPatent + '\'' +
                ", reOther='" + reOther + '\'' +
                '}';
    }

    public void preprocess() {
        if (patentType != null) {
            patentType = patentType.trim();
        }

        if (patentNum != null) {
            patentNum = patentNum.trim().replace(",", "");
        }

        if (firstInventor != null) {
            firstInventor = firstInventor.trim();
        }

        if (pubDate != null) {
            pubDate = pubDate.trim();
        }

        if (name != null) {
            name = name.trim();
        }

        if (inventor != null) {
            inventor = inventor.replace("<b>", "").replace("</b>", "").replace("td", "font");
            inventor = new Html(inventor).xpath("//font/text()").get();
            if (inventor != null) {
                inventor = inventor.trim();
            }
        }

        if (assignee != null){
            assignee = assignee.replace("<b>", "").replace("</b>", "").replace("td", "font");
            assignee = new Html(assignee).xpath("//font/text()").get();
            if (assignee != null) {
                assignee = assignee.trim();
            }
        }

        if (familyId != null) {
            familyId = familyId.trim();
        }

        if (appNum != null) {
            appNum = appNum.trim();
        }

        if (appDate != null) {
            appDate = appDate.trim();
        }
    }
}
